package methodref02;

import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

/**
 * 静态方法引用:
 *  前提:
 *     引用的方法和Lambda表达式对应接口中的抽象方法形参类型要保持一致
 *  格式:
 *   类名::静态方法名
 * 工具类中静态方法比较多:Arrays(数组工具类),Collections(集合工具类)
 *   Arrays类:
 *     public static String toString(int[] a):将数组中的元素拼接成一个字符串返回,格式:[元素1, 元素2, 元素3,...]
 *   Collections类:
 *    public static <T extends Comparable<? super T>> void sort(List<T> list):对传入的List集合进行排序(默认从小到大)
 */
public class MethodRefDemo02 {
    @Test
    public void test01(){
        int[] arr = {3, 7, 9};
        //Function<int[], String> f = array -> Arrays.toString(array);
        Function<int[], String> f = Arrays::toString;
        System.out.println(f.apply(arr));
    }

    @Test
    public void test02(){
        List<Integer> integers = Arrays.asList(1, 7, 12, 5, 23);

        //Consumer<List<Integer>> c = list -> Collections.sort(list);
        Consumer<List<Integer>> c = Collections::sort;
        c.accept(integers);
        System.out.println(integers);
    }
}

/**
 * class MethodRefDemo02$$Lambda01 implements Function<int[], String>{
 *     public String apply(int[] t){
 *        return Arrays.toString(t);
 *     }
 * }
 *
 * class MethodRefDemo02$$Lambda01 implements Consumer<List<Integer>>{
 *     public void accept(List<Integer> t){
 *         Collections.sort(t);
 * }
 *
 *
 *
 *
 */
